'use strict';
var transDate = require('../../../../module/transDate');
var app = getApp();

function initForm(info, form) {
    //将用户信息保存在全局变量的第一项
    app.globalData.user_form[0] = {};
    //保存用户填写的是哪一张表
    app.globalData.user_form[0].fill_form_id = form[0].form_id;
    app.globalData.user_form[0].fill_item = 'header';
    var time = Date.now();
    app.globalData.user_form[0].fill_time = transDate(time);
    app.globalData.user_form[0].fill_id = time;
    app.globalData.user_form[0].fill_country = info.country;
    app.globalData.user_form[0].fill_province = info.province;
    app.globalData.user_form[0].fill_city = info.city;
    app.globalData.user_form[0].fill_nickName = info.nickName;
    app.globalData.user_form[0].fill_language = info.language;
    app.globalData.user_form[0].fill_form_org = form[0].form_org;
    //添加所有的是否必填项
    for (var i = 1; i < form.length; i++) {
        if (form[i].hasOwnProperty('item_nec') == false) {
            app.globalData.user_form[i] = {};
            app.globalData.user_form[i].fill_item_nec = false;
        } else if (form[i].item_nec == true) {
            app.globalData.user_form[i] = {};
            app.globalData.user_form[i].fill_item_nec = true;
        }
    }
    //添加所有的项目类别
    for (var i = 1; i < form.length; i++) {
        app.globalData.user_form[i].fill_item = form[i].item;
    }
    //添加所有的问题
    for (var i = 1; i < form.length; i++) {
        app.globalData.user_form[i].fill_q = form[i].item_name;
    };
}
module.exports = initForm;